package StudyCode.summary.mycollection;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateUnmodifiableMapFromMap {
	public static void main(String[] argv) {
		System.out.println(map());
	}

	public static <K, V> Map<K, V> map(final Map.Entry<K, V>... entries) {
		final HashMap<K, V> map = new HashMap<K, V>(entries.length);
		for (final Map.Entry<K, V> entry : entries) {
			map.put(entry.getKey(), entry.getValue());
		}
		return Collections.unmodifiableMap(map);
	}

	public static <K, V> Map<K, V> map() {
		return new HashMap<K, V>();
	}


	public static <K, V> Map<K, V> unmodifiableMap(
			final Map<? extends K, ? extends V> m) {
		return (m == null) ? Collections.<K, V>emptyMap() : Collections
				.unmodifiableMap(m);
	}
}
